<?php

class adminProducts extends Controller
{
    public function index()
    {
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();
    	
	    $products = $this->model->getAllProducts();
		$categories = $this->model->getCategories();
		$digital_contents =  $this->model->getAllDigitalContent();
	    //print "Categories Are : <pre>" . print_r($categories,true) . "</pre>";exit;
        // $amount_of_digitalContents = $this->model->getamoutDigitalContent();
	
        // load views
        require APP . 'views/admin_templates/header.php';
        require APP . 'views/adminProducts/index.php';
        require APP . 'views/admin_templates/footer.php';
    }

    public function addProduct()
    {
		$result = 0;
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();
    	
        if (isset($_POST["submit_add_Product"])) {
			$image = $this->model->uploadFile($_FILES);
            $this->model->addProduct($_POST["product_name_ar"],$_POST["product_description_ar"],$_POST["product_name_en"],$_POST["product_description_en"],$image,$_POST["minprice"],$_POST["maxprice"],$_POST["colour"],$_POST["weight"],$_POST["size"],$_POST["legnth"],$_POST["weidth"],$_POST["minnumber"],$_POST["maxnumber"],$_POST["type_ar"],$_POST["type_en"],$_POST["historical_description_ar"],$_POST["historical_description_en"],$_POST["category_id"],$_POST["digital_content_id"]);         
		}
		
		header('location: ' . URL . 'adminProducts?result='.$result);
	}
	
	public function deleteProduct($product_id)
    {
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();
    	
        if (isset($product_id)) {
            $this->model->deleteProduct($product_id);
        }

        header('location: ' . URL . 'adminProducts');
    }
	

	public function editProduct($product_id)
    {
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();
    	
        if (isset($product_id)) {

        	$product = $this->model->getProduct($product_id);

            //require APP . 'views/_templates/header.php';
			 require APP . 'views/admin_templates/header.php';
            require APP . 'views/adminProducts/edit.php';
            //require APP . 'views/_templates/footer.php';
			   require APP . 'views/admin_templates/footer.php';
        } else {
            header('location: ' . URL . 'adminProducts/index');
        }
    }
	public function updateProduct()
    {
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();
    	
        if (isset($_POST["update_product"])) {
            $this->model->updateProduct($_POST["product_name_ar"],$_POST["product_description_ar"],$_POST["product_name_en"],$_POST["product_description_en"],$_POST["image"],$_POST["minprice"],$_POST["maxprice"],$_POST["colour"],$_POST["weight"],$_POST["size"],$_POST["legnth"],$_POST["weidth"],$_POST["minnumber"],$_POST["maxnumber"],$_POST["type_ar"],$_POST["type_en"],$_POST["historical_description_ar"],$_POST["historical_description_en"],$_POST["product_id"],$_POST["status"]);
         header('location: ' . URL . 'adminProducts');
        }
        header('location: ' . URL . 'adminProducts/index');

    }
}
